package com.kaiyiweitong.tongxing.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.kaiyiweitong.tongxing.R;

/**
 * Created by Administrator on 2017/12/26 0026.
 */

public class GoodServiceAdapter extends RecyclerView.Adapter {
    private Context mContext;
    private final LayoutInflater mInflater;
    private OnClickListener mListener;

    public interface OnClickListener {
        void onClick(int position);
    }

    public GoodServiceAdapter(Context context,OnClickListener listener) {
        mContext = context;
        mInflater = LayoutInflater.from(context);
        mListener=listener;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.item_good_service, null);
        MyViewHolder myViewHolder = new MyViewHolder(view);
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        MyViewHolder viewHolder = (MyViewHolder) holder;
        viewHolder.root.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mListener.onClick(position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return 10;
    }

    private class MyViewHolder extends RecyclerView.ViewHolder {
        private LinearLayout root;
        public MyViewHolder(View itemView) {
            super(itemView);
            root=itemView.findViewById(R.id.root);
        }
    }
}
